package com.ch1.kafka001.hello_kafka;

import com.ch1.kafka001.constant.KafkaInfo;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringSerializer;

import java.io.Serializable;
import java.util.Properties;

public class HelloKafkaProducer {
    public static void main(String[] args) {
        Properties properties = new Properties();
        properties.put("bootstrap.servers", KafkaInfo.HOST);
        properties.put("key.serializer", StringSerializer.class);
        properties.put("value.serializer",StringSerializer.class);

        KafkaProducer<String,String> producer = new KafkaProducer<String, String>(properties);

        try{

            ProducerRecord<String,String> record;
            try{
                for(int i=0;i<4;i++){
                    record = new ProducerRecord<String, String>("test2",null,"king"+(i*100));
                    producer.send(record);
                    System.out.println("king"+(i*100)+" is send..");
                }
            }catch (Exception e){
                e.printStackTrace();
            }

        }finally {
            producer.close();
        }
    }
}
